package com.purchase.util;

import java.util.Random;

/**
 * 邀请码生成
 */
public class InviteCodeUtil {

    private static final String[] storeInvitationChars = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"
            , "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

    /**
     * 生成六位邀请码
     * @param place 创建几位邀请码
     * @return
     */
    public static String generateCode(int place) {
        StringBuilder randomStr = new StringBuilder();
        for (int i = 0; i < place; i++) {
            Random random = new Random();
            int randomIndex = random.nextInt(36);
            randomStr.append(storeInvitationChars[randomIndex]);
        }
        return String.valueOf(randomStr);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100000; i++) {
            System.out.println(InviteCodeUtil.generateCode(6));
        }
    }

}
